<template>
  <div>
    <div style="margin: 10px auto">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-select
            clearable
            v-model="queryModel.siteId"
            placeholder="请选择站点"
          >
            <el-option
              v-for="obj in siteIds"
              :key="obj.siteId"
              :label="obj.siteName"
              :value="obj.siteId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            clearable
            v-model="queryModel.templateId"
            placeholder="请选择模板"
          >
            <el-option
              v-for="obj in templateIds"
              :key="obj.templateId"
              :label="obj.templateName"
              :value="obj.templateId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="queryModel.pageAliase"
            placeholder="请输入页面别名"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success" round @click="query">查询</el-button>
          <router-link to="/cms/page/add">
            <el-button type="primary" round>添加</el-button>
          </router-link>

          <el-button round @click="toAdd">添加2</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table :data="pageList" border style="width: 100%">
      <el-table-column fixed="left" prop="pageId" label="ID" width="220">
      </el-table-column>
      <el-table-column
        fixed="left"
        prop="pageCreateTime"
        label="日期"
        width="120"
      >
      </el-table-column>

      <el-table-column prop="pageName" label="页面名称"> </el-table-column>
      <el-table-column prop="pageAliase" label="页面别名"> </el-table-column>
      <el-table-column label="物理路径">
        <template slot-scope="scope">
          {{ scope.row.pagePhysicalPath }}
        </template>
      </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <router-link
            :to="{
              path: '/cms/page/edit',
              query: { pageId: scope.row.pageId },
            }"
          >
            <el-button type="text" size="small">编辑</el-button>
          </router-link>
          <el-button type="text" size="small" @click="del(scope.row.pageId)"
            >删除</el-button
          >
          <el-button type="text" size="small" @click="del(scope.row.pageId)"
            >页面预览</el-button
          >
          <el-button type="text" size="small" @click="del(scope.row.pageId)"
            >页面发布</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="page"
      background
      @size-change="sizeChange"
      @current-change="pageChange"
      :page-sizes="[5, 10, 20, 50]"
      :current-page="page"
      layout="total, sizes,prev, pager, next"
      :total="total"
      :page-size="pageSize"
    >
    </el-pagination>
  </div>
</template>

<script>
import { page_list, page_del } from "@/module/cmspage/api/cmspage";
export default {
  methods: {
    handleClick(row) {
      console.log(row);
    },
    query() {
      // console.log(this.queryModel)
      page_list(this.page, this.pageSize, this.queryModel).then((res) => {
        console.log(res);
        this.pageList = res.queryResult.list;
        this.total = res.queryResult.total;
      });
    },
    sizeChange(size) {
      this.pageSize = size;
      console.log(size);
      this.query();
    },
    pageChange(page) {
      console.log(page);
      this.page = page;
      this.query();
    },
    toAdd() {
      this.$router.push("/cms/page/add");
    },
    del(pageId) {
      console.log(pageId);
      this.$confirm("此操作将永久删除此条信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          page_del(pageId).then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.query();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },

  data() {
    return {
      total: 100,
      pageSize: 5,
      page: 1,
      queryModel: {
        templateId: null,
        siteId: null,
        pageAliase: null,
      },
      templateIds: [
        { templateId: "5a962b52b00ffc514038faf7", templateName: "首页" },
        { templateId: "5a962c16b00ffc514038fafd", templateName: "分类导航" },
      ],
      siteIds: [{ siteId: "5a751fab6abb5044e0d19ea1", siteName: "门户主站" }],
      pageList: [
        // {
        //   siteId: "5a751fab6abb5044e0d19ea1",
        //   pageId: "5a961ff6b00ffc5a9cdebaea",
        //   pageName: "4028e58161bd22e60161bd23672a0001.html",
        //   pageAliase: "课程详情页面",
        //   pageWebPath: "/course/",
        //   pageParameter: null,
        //   pagePhysicalPath:
        //     "E:\\jiaoyu\\eduUI01\\yh-ui-pc-static-portal\\course\\detail\\",
        //   pageType: "1",
        //   pageTemplate: null,
        //   pageHtml: null,
        //   pageStatus: null,
        //   pageCreateTime: "2018-02-28T03:20:20.988+0000",
        //   templateId: "5a925be7b00ffc4b3c1578b5",
        // },
      ],
      search: null,
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1519 弄",
          zip: 200333,
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1516 弄",
          zip: 200333,
        },
      ],
    };
  },
  beforeCreate() {
    console.log("beforeCreate");
  },
  created() {
    console.log("created");
    this.query();
  },
  beforeMount() {
    console.log("beforeMount");
  },
  mounted() {
    console.log("mounted");
  },
  destroyed() {
    console.log("destroyed");
  },
};
</script>
<style scoped>
.page {
  float: right;
  margin-top: 10px;
}
</style>